#ifndef PAGE_H_
#define PAGE_H_

/*
Copyright (C) 2011 Salil Bhagurkar

This file is part of illusion

illusion is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

illusion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with illusion.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <kernel/types.h>

#define PAGE_PRESENT 1
#define PAGE_USER 2
#define PAGE_WRITE 4

#define MAP_NR_PAGES 4096
#define PAGE_SIZE 4096
#define PAGE_ADDRESS_MASK (~(PAGE_SIZE - 1))
#define NR_WORDS (MAP_NR_PAGES / (8 * sizeof(unsigned long)))
#define PAGEMAP_SZ (NR_WORDS * sizeof(unsigned long))
#define PAGEMAP_RANGE (MAP_NR_PAGES * PAGE_SIZE)
#define PAGEMAP_ADDRESS_MASK (~(PAGEMAP_RANGE - 1))


struct pagemap {
	void *base;
	uint_t free_pages;
	u32 bitmap[NR_WORDS];
	struct pagemap *next, *prev;
};

void debug_phys_pagemaps();

void phys_create_range(struct pagemap *map, ptr_t address);
int phys_is_page(void *address);
int phys_reserve_pages(void *address, uint_t count);
int phys_free_pages(void *address, uint_t count);
void *phys_get_pages(uint_t count);
uint_t phys_count_free();
uint_t phys_total_count();

int page_sys_init();


#endif /* PAGE_H_ */
